package util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

import beans.Informacoes;
import beans.Usuario;

public abstract class HibernateFactory {

	private static SessionFactory sessionFactory = null;

	public static SessionFactory getSessionFactory() {
		
		/*Se for a primeira vez que tenta recuperar um sessionFactory o hibernate
		 * cria as tabelas do banco baseado nos mapeamentos xml*/
		if(sessionFactory == null){
			 Configuration config = new Configuration();
		   	 config.configure("hibernate.cfg.xml");
		   	 
		   	 /*Caso nao queira perder os dados no banco apenas comente estas duas linhas */
		   	 /*SchemaExport export = new SchemaExport(config);
		   	 export.create(true, true);*/
		   	 
		   	 sessionFactory = config.buildSessionFactory();
		   	 
		   
		}
		
		return sessionFactory;
	}
	
	
}
